#!/usr/bin/bash

if [[ $1 == "" ]] ; then
	echo "keys: on off
	dby-wifi on - wifi on
	dby-wifi connect $name - wifi connect to $name
	dby-wifi check - wifi check actives wifi
	dby-wifi off - wifi off
"
	exit 1
else
	key=$1
	name=$2
fi



if [[ on == $key ]] ; then
	echo adapter on
	iwctl adapter phy0 set-property Powered on

	echo device on
	iwctl device wlan0 set-property Powered on

	iwctl wsc wlan0 start-pin
	iwctl station wlan0 scan

	# connect to wifi: - commit this, if you not want connect:
	# sway-tools-wifi connect
elif [[ off == $key ]] ; then
	echo disconnect
	iwctl station wlan0 disconnect 

	echo device off
	iwctl device wlan0 set-property Powered off

	echo adapter off
	iwctl adapter phy0 set-property Powered off
elif [[ connect == $key ]] ; then
	iwctl station wlan0 get-networks

	# check and write name wifi
	name=$2
	if [[ "" == $name ]] ; then
		# default
		name=bochkor_wifi
	fi

	echo connect
	iwctl station wlan0 connect $name

	# check wifi: - commit this, if you not want check:
	# sway-tools-wifi check
elif [[ check == $key ]] ; then
	echo check connecting on link 0.0.0.0
	ping -c 4 0.0.0.0
	
	echo check connect on link gnu.org
	ping -c 4 gnu.org
fi


